

<template>
  <div>
    <div class="flex-input">
      <div>
        <el-input v-model="getListParme.account"   placeholder="职工号" />
      </div>
      <div>
        <el-input v-model="getListParme.name"  placeholder="姓名" />
      </div>
      <div>
        <el-select
            v-model="getListParme.titleIdList"
            multiple
            collapse-tags
            filterable
            collapse-tags-tooltip
            placeholder="职称"
            style="width: 100%"
            @focus="getzhichengOptions"
        >
          <el-option
              v-for="item in zhichengOptions"
              :key="item.codeColumn"
              :label="item.valueColumn"
              :value="item.codeColumn"
          />
        </el-select>
      </div>
      <div >
        <el-select
            v-model="getListParme.subjectIdList"
            multiple
            collapse-tags
            filterable
            collapse-tags-tooltip
            placeholder="一级学科"
            style="width: 100%"
            @focus="getyijixuekeOptions"
        >
          <el-option
              v-for="item in yijixuekeOptions"
              :key="item.id"
              :label="item.label"
              :value="item.id"
          />
        </el-select>
      </div>
      <div >
        <el-select
            v-model="getListParme.eduDegreeIdList"
            multiple
            collapse-tags
            filterable
            collapse-tags-tooltip
            placeholder="最后学位"
            style="width: 100%"
        >
          <el-option
              v-for="item in zuihouxueweiOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
          />
        </el-select>
      </div>
      <div>
        <el-select
            v-model="getListParme.unitIdList"
            multiple
            collapse-tags
            filterable
            collapse-tags-tooltip
            placeholder="所属单位"
            style="width: 100%"
            @focus="getshuoshudanweiOptions"
        >
          <el-option
              v-for="item in shuoshudanweiOptions"
              :key="item.codeColumn"
              :label="item.valueColumn"
              :value="item.codeColumn"
          />
        </el-select>
      </div>

      <div style="min-width: 180px;border-right: 1px solid #d7d6d6;margin-right: 0px">
        <el-button icon="ArrowLeft"  @click="searchOpen = !searchOpen">更多</el-button>
<!--        <el-button icon="ArrowLeft" @click="drawer = true">更多</el-button>-->
        <el-button type="primary" icon="Search" @click="searchBtnList()">查询</el-button>
      </div>

    </div>
    <div v-show="searchOpen" class="sss">
      <el-select
          v-model="getListParme.sexIdList"
          multiple
          collapse-tags
          filterable
          collapse-tags-tooltip
          placeholder="性别"

      >
        <el-option
            v-for="item in sex"
            :key="item.value"
            :label="item.label"
            :value="item.value"
        />
      </el-select>
      <el-select
          v-model="getListParme.hrUnitIdList"
          multiple
          collapse-tags
          filterable
          collapse-tags-tooltip
          placeholder="人事单位"

          @focus="getrenshidanweiOptions"
      >
        <el-option
            v-for="item in renshidanweiOptions"
            :key="item.codeColumn"
            :label="item.valueColumn"
            :value="item.codeColumn"
        />
      </el-select>
      <el-select
          v-model="getListParme.personStateList"
          multiple
          collapse-tags
          filterable
          collapse-tags-tooltip
          placeholder="在职情况"
      >
        <el-option
            v-for="item in zaizhiqingkuangOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
        />
      </el-select>
      <el-input
          v-model="getListParme.nameEn"
          placeholder="英文名字"
      />
      <el-input
          v-model="getListParme.email"
          placeholder="电子邮件"
      />
      <el-input
          v-model="getListParme.mobile"
          placeholder="手机号"
      />
      <el-input
          v-model="getListParme.idCard"
          placeholder="身份证号/护照号"
      />
      <el-input
          v-model="getListParme.graduateSchool"
          placeholder="毕业院校"
      />
      <el-input
          v-model="getListParme.researchFiel"
          placeholder="研究方向"
      />
    </div>
    <div>
      <el-table
          border
          ref="multipleTableRef"
          :data="tableData"
          style="width: 100%"
          default-expand-all
      >
        <el-table-column type="selection" :selectable="selectable" width="55" />
        <el-table-column label="职工号">
          <template #default="scope">{{ scope.row.account }}</template>
        </el-table-column>
        <el-table-column  label="姓名">
        <template #default="scope">
          <div style="cursor: pointer;color: #2A91FE">
            <span @click="openpeopledetails(scope.row)">{{ scope.row.name }}</span>
          </div>
        </template>
        </el-table-column>
        <el-table-column property="titleName" label="职称" />
        <el-table-column property="firstLevel" label="一级学科" />
        <el-table-column label="最后学位">
          <template #default="{ row }">
            {{ getDegreeName(row.eduDegreeId) }}
          </template>
        </el-table-column>
<!--        <el-table-column property="eduDegreeId" label="最后学位" />-->
        <el-table-column label="科研详情">
          <template #default="scope">
            <div style="cursor: pointer;color: #2A91FE">
              <span @click="GoDetailsPage(scope.row)">查看</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column property="unitName" label="所属单位" />
        <el-table-column  sortable="custom" prop="checkstatus" label="审核状态">
          <template #default="{ row }">
            <CommonLabel
                :dataList="checkStatusList"
                valueKey="dictValue"
                labelKey="dictLabel"
                :value="row.checkstatus"
            />
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" min-width="120">
          <template #default="scope">
            <!-- 科研秘书操作 -->
            <!-- 暂存 -1 或审批不通过 3 状态，科研秘书可编辑和删除 -->
            <el-button v-if="(scope.row.checkstatus == -1 || scope.row.checkstatus == 3) && verifyRoleType.isKyms()" link type="primary" size="small" @click="handleClick(scope.row)">
              编辑
            </el-button>
            <el-button v-if="(scope.row.checkstatus == -1 || scope.row.checkstatus == 3) && verifyRoleType.isKyms()" link type="danger" size="small" @click="deleteRow(scope.row)">
              删除
            </el-button>
            <!-- 审批中状态 1，科研秘书可撤销 -->
            <el-button v-if="scope.row.checkstatus == 1 && verifyRoleType.isKyms()" link type="warning" size="small" @click="handleCancel(scope.row)">
              撤销
            </el-button>
            <!-- 审核通过状态 2，科研秘书可完善 -->
            <el-button v-if="scope.row.checkstatus == 2 && verifyRoleType.isKyms()" link type="primary" size="small" @click="handleClick(scope.row)">
              完善
            </el-button>

            <!-- 科研管理员操作 -->
            <!-- 暂存 -1 或审批不通过 3 状态，科研管理员可编辑 -->
            <el-button v-if="(scope.row.checkstatus == -1 || scope.row.checkstatus == 3) && verifyRoleType.iskycgly()" link type="primary" size="small" @click="handleClick(scope.row)">
              编辑
            </el-button>
            <el-button v-if="(scope.row.checkstatus == -1 || scope.row.checkstatus == 3) && verifyRoleType.iskycgly()" link type="danger" size="small" @click="deleteRow(scope.row)">
              删除
            </el-button>
            <!-- 审批中状态 1，科研管理员可编辑 -->
            <el-button v-if="scope.row.checkstatus == 1 && verifyRoleType.iskycgly()" link type="primary" size="small" @click="handleClick(scope.row)">
              编辑
            </el-button>
            <el-button v-if="scope.row.checkstatus == 1 && verifyRoleType.iskycgly()" link type="success" size="small"  @click="openauditBtn(scope.row)">审核</el-button>
            <!-- 审核通过状态 2，科研管理员可编辑 -->
            <el-button v-if="scope.row.checkstatus == 2 && verifyRoleType.iskycgly()" link type="primary" size="small" @click="handleClick(scope.row)">
              编辑
            </el-button>
            <el-button v-if="scope.row.checkstatus == 2 && verifyRoleType.iskycgly()" link type="danger" size="small" @click="deleteRow(scope.row)">
              删除
            </el-button>

<!--            <el-button v-if="!(verifyRoleType.isKyms() && scope.row.checkstatus == 2)" link type="primary" size="small"  @click="handleClick(scope.row)">-->
<!--              编辑-->
<!--            </el-button>-->
<!--            <el-button v-if="verifyRoleType.isKyms() && scope.row.checkstatus == 2" link type="primary" size="small"  @click="handleClick(scope.row)">-->
<!--              完善-->
<!--            </el-button>-->
<!--            <el-button  v-if="verifyRoleType.isKyms() && scope.row.checkstatus == '1'" link type="warning" size="small" @click="handleCancel(scope.row)">撤销</el-button>-->
<!--            <el-button v-if="verifyRoleType.iskycgly() && scope.row.checkstatus == '1'" link type="success" size="small"  @click="openauditBtn(scope.row)">审核</el-button>-->
<!--            <el-button v-if="scope.row.checkstatus == -1 || scope.row.checkstatus == 3" link type="danger" size="small" @click="deleteRow(scope.row)">删除</el-button>-->
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div class="example-pagination-block">
      <el-pagination
          layout="->,prev, pager, next, total"
          :total="count"
          currentPage1="10"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
      />
    </div>
  </div>
  <el-drawer v-model="drawer" :direction="direction">
    <template #header>
      <h4>选择条件</h4>
    </template>
    <template #default>
      <div class="sss">
        <el-select
            v-model="getListParme.sexIdList"
            multiple
            collapse-tags
            filterable
            collapse-tags-tooltip
            placeholder="性别"
            size="small"
            style="width: 200px"
        >
          <el-option
              v-for="item in sex"
              :key="item.value"
              :label="item.label"
              :value="item.value"
          />
        </el-select>
        <el-select
            v-model="getListParme.hrUnitIdList"
            multiple
            size="small"
            collapse-tags
            filterable
            collapse-tags-tooltip
            placeholder="人事单位"
            style="width: 200px"
            @focus="getrenshidanweiOptions"
        >
          <el-option
              v-for="item in renshidanweiOptions"
              :key="item.codeColumn"
              :label="item.valueColumn"
              :value="item.codeColumn"
          />
        </el-select>
        <el-select
            v-model="getListParme.personStateList"
            multiple
            size="small"
            collapse-tags
            filterable
            collapse-tags-tooltip
            placeholder="在职情况"
            style="width: 200px"
        >
          <el-option
              v-for="item in zaizhiqingkuangOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
          />
        </el-select>
        <el-input
            v-model="getListParme.nameEn"
            style="width: 200px"
            size="small"
            placeholder="英文名字"
        />
        <el-input
            v-model="getListParme.email"
            style="width: 200px"
            size="small"
            placeholder="电子邮件"
        />
        <el-input
            v-model="getListParme.mobile"
            style="width: 200px"
            size="small"
            placeholder="手机号"
        />
        <el-input
            v-model="getListParme.idCard"
            style="width: 200px"
            size="small"
            placeholder="身份证号/护照号"
        />
        <el-input
            v-model="getListParme.graduateSchool"
            style="width: 200px"
            size="small"
            placeholder="毕业院校"
        />
        <el-input
            v-model="getListParme.researchFiel"
            style="width: 200px"
            size="small"
            placeholder="研究方向"
        />
      </div>
    </template>
    <template #footer>
      <div style="flex: auto">
        <el-button @click="cancelClick">关闭</el-button>
        <el-button type="primary" @click="searchBtnList">查询</el-button>
      </div>
    </template>
  </el-drawer>

  <el-dialog v-model="dialogFormVisible" title="编辑" width="70%">
    <el-form
        ref="ruleFormRef"
        :model="ruleForm"
        :rules="rules"
        label-width="120px"
        class="demo-ruleForm"
        :size="formSize"
        status-icon
    >
      <div class="dialog-flex">
        <div>
          <el-form-item label="姓名" prop="name">
            <el-input v-model="ruleForm.name" />
          </el-form-item>
          <el-form-item label="职工号" prop="account">
            <el-input v-model="ruleForm.account" />
          </el-form-item>
          <el-form-item label="性别" prop="sexId">
            <el-radio-group v-model="ruleForm.sexId">
              <el-radio label="男" value="1"/>
              <el-radio label="女" value="0"/>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="人事单位" prop="hrUnitId">
            <el-select @focus="getrenshidanweiOptions" v-model="ruleForm.hrUnitId" placeholder="请选择人事单位">
              <el-option
                  v-for="item in renshidanweiOptions"
                  :key="item.codeColumn"
                  :label="item.valueColumn"
                  :value="item.codeColumn"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="所属单位" prop="unitId">
            <el-select @focus="getshuoshudanweiOptions" v-model="ruleForm.unitId" placeholder="请选择所属单位">
              <el-option
                  v-for="item in shuoshudanweiOptions"
                  :key="item.codeColumn"
                  :label="item.valueColumn"
                  :value="item.codeColumn"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="职称" prop="titleId">
            <el-select @focus="getzhichengOptions" value-key="value" v-model="ruleForm.titleId" placeholder="请选择所属单位">
              <el-option
                  v-for="item in zhichengOptions"
                  :key="item.codeColumn"
                  :label="item.valueColumn"
                  :value="item.codeColumn"

              />
            </el-select>
          </el-form-item>
          <el-form-item label="科学研究领域" prop="searchClassId">
            <el-select @focus="getkexueyanjiuOptions" v-model="ruleForm.searchClassId" placeholder="请选择所属单位">
              <el-option
                  v-for="item in kexueyanjiuOptions"
                  :key="item.codeColumn"
                  :label="item.valueColumn"
                  :value="item.codeColumn"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="一级学科" prop="searchId">
            <el-select
                v-model="ruleForm.searchId"
                placeholder="请选择一级学科"
                @focus="getyijixuekeOptions"
            >
              <el-option
                  v-for="item in yijixuekeOptions"
                  :key="item.id"
                  :label="item.label"
                  :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="职称级别" prop="titleRank">
            <el-radio-group v-model="ruleForm.titleRank">
              <el-radio label="正高级" value="ZGJ"/>
              <el-radio label="副高级" value="FGJ"/>
              <el-radio label="中级" value="ZJ"/>
              <el-radio label="初级" value="CJ"/>
              <el-radio label="其他" value="QT"/>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="最后学位" prop="eduDegreeId">
            <el-radio-group v-model="ruleForm.eduDegreeId">
              <el-radio label="博士" value="2"/>
              <el-radio label="硕士" value="3"/>
              <el-radio label="学士" value="4"/>
              <el-radio label="无" value="999"/>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="最后学历" prop="eduLevelId">
            <el-radio-group v-model="ruleForm.eduLevelId">
              <el-radio label="博士研究生" value="0"/>
              <el-radio label="硕士研究生" value="1"/>
              <el-radio label="本科" value="2"/>
              <el-radio label="大专" value="3"/>
              <el-radio label="中专" value="4"/>
              <el-radio label="其他" value="5"/>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="在职情况" prop="personState">
            <el-radio-group v-model="ruleForm.personState">
              <el-radio label="在职" value="1"/>
              <el-radio label="退休" value="2"/>
              <el-radio label="离职" value="3"/>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="是否统计" prop="isStat">
            <el-radio-group v-model="ruleForm.isStat">
              <el-radio label="统计" value="1"/>
              <el-radio label="不统计" value="0"/>
            </el-radio-group>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="政治面貌" :label-width="formLabelWidth">
            <el-select @focus="getzhengzhimianmaoOptions" v-model="ruleForm.polityId" placeholder="请选择政治面貌">
              <el-option
                  v-for="item in zhengzhimianmaoOptions"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="杰出人才"  :label-width="formLabelWidth">
            <el-checkbox-group v-model="ruleForm.honorTitleId">
              <el-checkbox label="院士" value="1" name="type" />
              <el-checkbox label="突出青年" value="2" name="type" />
              <el-checkbox label="长江学者" value="3" name="type" />
              <el-checkbox label="其他" value="4" name="type" />
            </el-checkbox-group>
          </el-form-item>
          <el-form-item label="硕导/博导"  :label-width="formLabelWidth">
            <el-radio-group v-model="ruleForm.tutorTypeId">
              <el-radio label="博导" value="1"/>
              <el-radio label="硕导"  value="2"/>
              <el-radio label="非导师"  value="3"/>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="英文名" :label-width="formLabelWidth">
            <el-input v-model="ruleForm.nameEn" autocomplete="off" />
          </el-form-item>
          <el-form-item label="电子邮件" :label-width="formLabelWidth" prop="email">
            <el-input v-model="ruleForm.email" autocomplete="off" />
          </el-form-item>
          <el-form-item label="手机号" :label-width="formLabelWidth" prop="mobile">
            <el-input v-model="ruleForm.mobile" autocomplete="off" />
          </el-form-item>
          <el-form-item label="办公电话" :label-width="formLabelWidth" prop="telOffice">
            <el-input v-model="ruleForm.telOffice" autocomplete="off" />
          </el-form-item>
          <el-form-item label="出生年月" :label-width="formLabelWidth">
            <el-date-picker
                v-model="ruleForm.birthday"
                type="date"
                format="YYYY/MM/DD"
                value-format="YYYY-MM-DD"
                aria-label="选择时间"
                placeholder="选择时间"
            />
          </el-form-item>
          <el-form-item label="身份证号/护照号" :label-width="formLabelWidth">
            <el-input v-model="ruleForm.idCard" autocomplete="off" />
          </el-form-item>
          <el-form-item label="毕业院校" :label-width="formLabelWidth">
            <el-input v-model="ruleForm.graduateSchool" autocomplete="off" />
          </el-form-item>
          <el-form-item label="研究方向"  :label-width="formLabelWidth">
            <el-input v-model="ruleForm.researchField" type="textarea" />
          </el-form-item>
        </div>
      </div>
      <div>
        <el-form-item label="教育经历" :label-width="formLabelWidth">
          <el-input v-model="ruleForm.learnSpecialty" type="textarea" />
        </el-form-item>
        <el-form-item label="出国经历" :label-width="formLabelWidth">
          <el-input v-model="ruleForm.experienceAbroad" type="textarea" />
        </el-form-item>
        <el-form-item label="进修培训情况" :label-width="formLabelWidth">
          <el-input v-model="ruleForm.learning" type="textarea" />
        </el-form-item>
        <el-form-item label="学术及社会兼职" :label-width="formLabelWidth">
          <el-input v-model="ruleForm.parttime" type="textarea" />
        </el-form-item>
      </div>
      <div style="margin-left:35%">
        <el-form-item>

          <!-- 科研秘书可暂存、提交、关闭 -->
          <el-button v-if="verifyRoleType.isKyms() && (currentCheckStatus == -1 || currentCheckStatus == 3 )" style="text-align: center" type="primary" @click="submitForm(ruleFormRef,'-1')">
            暂存
          </el-button>
          <el-button v-if="verifyRoleType.isKyms() && (currentCheckStatus == -1 || currentCheckStatus == 3 )" style="text-align: center" type="primary" @click="submitForm(ruleFormRef, '1')">
            提交
          </el-button>
          <!-- 科研管理员在暂存或不通过、审批中状态 -->
          <el-button v-if="verifyRoleType.iskycgly() && (currentCheckStatus == -1 || currentCheckStatus == 3 || currentCheckStatus == 1)" style="text-align: center" type="primary" @click="submitForm(ruleFormRef,'-1')">
            暂存
          </el-button>
          <el-button v-if="verifyRoleType.iskycgly() && (currentCheckStatus == -1 || currentCheckStatus == 3 || currentCheckStatus == 1)" style="text-align: center" type="primary" @click="submitForm(ruleFormRef, '2')">
            保存并通过
          </el-button>
          <!-- 科研管理员在审核通过状态 -->
          <el-button v-if="(verifyRoleType.iskycgly() || verifyRoleType.isKyms()) && currentCheckStatus == 2" style="text-align: center" type="primary" @click="submitForm(ruleFormRef,'2')">
            保存
          </el-button>
          <el-button style="text-align: center" @click="resetForm(ruleFormRef)">关闭</el-button>


<!--          <el-button style="text-align: center" type="primary" @click="submitForm(ruleFormRef,'-1')">-->
<!--            暂存-->
<!--          </el-button>-->
<!--          <el-button v-if="verifyRoleType.isKyms()" style="text-align: center" type="primary" @click="submitForm(ruleFormRef, '1')">-->
<!--            提交-->
<!--          </el-button>-->
<!--          <el-button v-if="verifyRoleType.iskycgly()" style="text-align: center" type="primary" @click="submitForm(ruleFormRef,'2')">-->
<!--            保存并通过-->
<!--          </el-button>-->
<!--          <el-button style="text-align: center" @click="resetForm(ruleFormRef)">关闭</el-button>-->
        </el-form-item>
      </div>

    </el-form>
<!--      <div>-->
<!--        <el-form :model="form">-->
<!--          <el-form-item label="Promotion name" :label-width="formLabelWidth">-->
<!--            <el-input v-model="form.name" autocomplete="off" />-->
<!--          </el-form-item>-->
<!--          <el-form-item label="政治面貌" :label-width="formLabelWidth">-->
<!--            <el-select v-model="form.region" placeholder="Please select a zone">-->
<!--              <el-option label="Zone No.1" value="shanghai" />-->
<!--              <el-option label="Zone No.2" value="beijing" />-->
<!--            </el-select>-->
<!--          </el-form-item>-->
<!--          <el-form-item label="Activity type" prop="type" :label-width="formLabelWidth">-->
<!--            <el-checkbox-group v-model="ruleForm.type">-->
<!--              <el-checkbox label="Online activities" name="type" />-->
<!--              <el-checkbox label="Promotion activities" name="type" />-->
<!--              <el-checkbox label="Offline activities" name="type" />-->
<!--              <el-checkbox label="Simple brand exposure" name="type" />-->
<!--            </el-checkbox-group>-->
<!--          </el-form-item>-->
<!--          <el-form-item label="硕导/博导" prop="resource" :label-width="formLabelWidth">-->
<!--            <el-radio-group v-model="ruleForm.resource">-->
<!--              <el-radio label="男" />-->
<!--              <el-radio label="女" />-->
<!--            </el-radio-group>-->
<!--          </el-form-item>-->
<!--          <el-form-item label="英文名" :label-width="formLabelWidth">-->
<!--            <el-input v-model="form.name" autocomplete="off" />-->
<!--          </el-form-item>-->
<!--          <el-form-item label="电子邮件" :label-width="formLabelWidth">-->
<!--            <el-input v-model="form.name" autocomplete="off" />-->
<!--          </el-form-item>-->
<!--          <el-form-item label="手机号" :label-width="formLabelWidth">-->
<!--            <el-input v-model="form.name" autocomplete="off" />-->
<!--          </el-form-item>-->
<!--          <el-form-item label="办公电话" :label-width="formLabelWidth">-->
<!--            <el-input v-model="form.name" autocomplete="off" />-->
<!--          </el-form-item>-->
<!--          <el-form-item label="出生年月" :label-width="formLabelWidth">-->
<!--            <el-input v-model="form.name" autocomplete="off" />-->
<!--          </el-form-item>-->
<!--          <el-form-item label="身份证号/护照号" :label-width="formLabelWidth">-->
<!--            <el-input v-model="form.name" autocomplete="off" />-->
<!--          </el-form-item>-->
<!--          <el-form-item label="毕业院校" :label-width="formLabelWidth">-->
<!--            <el-input v-model="form.name" autocomplete="off" />-->
<!--          </el-form-item>-->
<!--          <el-form-item label="研究方向" prop="desc" :label-width="formLabelWidth">-->
<!--            <el-input v-model="ruleForm.desc" type="textarea" />-->
<!--          </el-form-item>-->
<!--        </el-form>-->

<!--      </div>-->

  </el-dialog>


  <audit
      ref="openaudit"
      @Getlist="fathergeilist"
  >
  </audit>
  <peopleDetails :activ="activ"  :obj="obj"  @close-dialog="activ = false"></peopleDetails>
  <DetailsPageVue ref="DetailsPage"></DetailsPageVue>
</template>
<script lang="ts" setup>
const searchOpen = ref(false)
import { verifyRoleType } from "@/utils/main";
import CommonLabel from "@/views/project/components/CommonLabel.vue";
import useDictFetch from "@/hooks/useDictFetch";
const checkStatusList = useDictFetch("bpm_process_instance_status"); //审核状态
import { DrawerProps, ElMessage, ElMessageBox} from "element-plus";
const drawer = ref(false) //更多在弹出
const direction = ref<DrawerProps['direction']>('rtl')
const radio1 = ref('Option 1')
import {exportList,getCategory,getPersonList,personDetails,updatePersonList,deletPersonList} from "@/api/researcherNavApi/researcherNavApi"
import {onMounted, reactive,ref} from "vue";
import peopleDetails from './../../../components/peopleDetails/peopleDetails.vue'
import search from "diagram-js/lib/features/search/search";
import {handleFileDownload} from './../../../utils/downloadSz'
//导出
const Export = () => {
  // 复制一份 getListParme 对象，避免修改原始数据
  //const requestData = { ...getListParme.value};
  exportList({
    ...getListParme.value
  })
      .then((res)=>{
        if (res.code === 500) {
          ElMessage({
            type: 'error',
            message: '数据库查询出错，请联系管理员检查 SQL 语句。'
          });
        } else if (!(res instanceof Blob)) {
          ElMessage({
            type: 'info',
            message: '响应数据不是 Blob 类型',
          })
        }else {
          handleFileDownload(res, '人员列表');
        }
      })
}


//撤销
import { cancelProcess } from "@/api/project/common";
//点击撤销
const handleCancel = async (row) => {
  try {
    const res = await cancelProcess(row.processInstanceId);
    if (res.data) {
      ElMessage({
        message: "操作成功！",
        type: "success",
      });
      fathergeilist()
    } else {
      ElMessage({
        message: "操作失败！",
        type: "warning",
      });
    }
  } catch (error) {
    console.log(error);
  }
};
//审核调用
import audit from  './audit.vue'
const openaudit = ref(null)
const openauditBtn = function (row){
  openaudit.value.openaudit(row)
}



//把表格展示最后学位
const getDegreeName = (degreeId) => {
  const degreeMap = {
    2: '博士',
    3: '硕士',
    4: '学士',
    999: '无'
  };
  return degreeMap[degreeId] || '未知';
};
function cancelClick() {
  drawer.value = false
}


const tableData =ref([])
// 删除
const deleteRow = (row) => {
  ElMessageBox.confirm(
      '确认！删除这条数据?',
      '提醒',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }
  )
      .then(() => {
        deletPersonList({id:row.id})
            .then((res)=>{
              if(res.code == 200){
                ElMessage({
                  type: 'success',
                  message: res.data,
                })
                fathergeilist()
                    .then((res)=>{
                      tableData.value = res.data.list
                      count.value = res.data.count
                    })
              }else {
                ElMessage({
                  type: 'info',
                  message: res.msg,
                })
              }
            })


      })
      .catch(() => {
        // ElMessage({
        //   type: 'info',
        //   message: 'Delete canceled',
        // })
      })
}
// 删除

// 编辑
// 用于记录当前审核状态 为按钮做判断
const currentCheckStatus = ref(0);
const handleClick =function (row){
  currentCheckStatus.value = row.checkstatus;
  // alert(row.checkstatus)
  dialogFormVisible.value = true
  getzhichengOptions()
  getyijixuekeOptions()
  getshuoshudanweiOptions()
  getrenshidanweiOptions()
  getkexueyanjiuOptions()
  getzhengzhimianmaoOptions()
  personDetails({id:row.id})
      .then((res)=>{
        Object.assign(ruleForm, {
          checkstatus: res.data[0].checkstatus, //审核状态
          name: res.data[0].name, //人名
          account:res.data[0].account, //职工号
          sexId:res.data[0].sexId,//性别
          hrUnitId: res.data[0].hrUnitId,//人事单位
          unitId:res.data[0].unitId,//所属单位
          titleId:res.data[0].titleId,//职称
          searchClassId: res.data[0].searchClassId,  //科学研究领域.
          searchId:res.data[0].searchId,//一级学科
          eduDegreeId:res.data[0].eduDegreeId,//最后学位
          titleRank:res.data[0].titleRank,//最后学位
          eduLevelId:res.data[0].eduLevelId,//最后学历
          personState:res.data[0].personState,//在职情况
          isStat:res.data[0].isStat,//是否统计
          polityId:res.data[0].polityId,//政治面貌
          honorTitleId:res.data[0] && res.data[0].honorTitleId
              ? res.data[0].honorTitleId.split(',')
              : [],//杰出人才
          tutorTypeId:res.data[0].tutorTypeId,//硕导/博导
          nameEn:res.data[0].nameEn,//英文名
          email:res.data[0].email,//电子邮件
          mobile:res.data[0].mobile,//手机号
          telOffice:res.data[0].telOffice,//办公电话
          birthday:res.data[0].birthday,//出生年月
          idCard:res.data[0].idCard,//身份证号
          graduateSchool:res.data[0].graduateSchool,//毕业院校
          researchField:res.data[0].researchField,//研究方向
          learnSpecialty:res.data[0].learnSpecialty,//教育经历
          experienceAbroad: res.data[0].experienceAbroad,//出国经历
          learning: res.data[0].learning,//进修培训情况
          parttime: res.data[0].parttime,//学术及社会兼职
          id:row.id,
          processInstanceId:row.processInstanceId
        });
      })
}
const dialogFormVisible = ref(false)
const formLabelWidth = '140px'
const formSize = ref('default')
const ruleFormRef = ref<FormInstance>()
const ruleForm = reactive<RuleForm>({
  checkstatus:'',
  submitType:'',
  name: '', //人名
  account:'', //职工号
  sexId:'',//性别
  hrUnitId: '',//人事单位
  unitId:'',//
  titleId:'',//职称
  searchClassId: '',  //科学研究领域.
  searchId:'',//一级学科
  eduDegreeId:'',//最后学位
  titleRank:'',//职称级别
  eduLevelId:'',//最后学历
  personState:'',//在职情况
  isStat:'',//是否统计
  polityId:'',//政治面貌
  honorTitleId:[],//杰出人才
  tutorTypeId:'',//硕导/博导
  nameEn:'',//英文名
  email:'',//电子邮件
  mobile:'',//手机号
  telOffice:'',//办公电话
  birthday:'',//出生年月
  idCard:'',//身份证号
  graduateSchool:'',//毕业院校
  learnSpecialty:'',//教育经历
  experienceAbroad: '',//出国经历
  learning: '',//进修培训情况
  parttime: '',//学术及社会兼职
  researchField:"",//研究方向
  processInstanceId:'',//流程实例id
})

interface RuleForm {
  checkstatus:string
  submitType:string
  name: string
  account:string
  sexId:string
  hrUnitId: string
  unitId: string
  titleId: string
  searchClassId: string
  searchId: string
  eduDegreeId: string
  titleRank: string
  eduLevelId: string
  personState: string
  isStat: string
  polityId: string
  honorTitleId: string[]
  tutorTypeId: string
  nameEn: string
  email: string
  mobile: string
  telOffice: string
  birthday: string
  idCard: string
  graduateSchool: string
  learnSpecialty: string
  experienceAbroad: string
  learning: string
  parttime: string
  researchField: string
  processInstanceId:string
}
const rules = reactive<FormRules<RuleForm>>({

  name: [
    { required: true, message: '请填写姓名', trigger: 'blur' },
    //{ min: 3, max: 5, message: 'Length should be 3 to 5', trigger: 'blur' },
  ],
  account: [
    { required: true, message: '请填写职工号', trigger: 'blur' },
  ],
  sexId: [
    {required: true, message: '请选择性别', trigger: 'change',},
  ],
  hrUnitId: [
    {required: true, message: '请选择人事单位', trigger: 'change',},
  ],
  unitId:[
    {required: true, message: '请选择所属单位', trigger: 'change',},
  ],
  titleId: [
    {required: true, message: '请选择职称', trigger: 'change',},
  ],
  searchClassId: [
    {required: true, message: '请选择科学研究领域', trigger: 'change',},
  ],
  searchId: [
    {required: true, message: '请选择科学一级学科', trigger: 'change',},
  ],
  eduDegreeId:[
    {required: true, message: '请选择最后学位', trigger: 'change',},
  ],
  titleRank:[
    {required: true, message: '请选择最后学位', trigger: 'change',},
  ],
  eduLevelId:[
    {required: true, message: '请选择最后学位', trigger: 'change',},
  ],
  personState:[
    {required: true, message: '请选择在职情况', trigger: 'change',},
  ],
  isStat:[
    {required: true, message: '请选择统计', trigger: 'change',},
  ],

  region: [
    {required: true, message: 'Please select Activity zone', trigger: 'change',},
  ],
  count: [
    {required: true, message: 'Please select Activity count', trigger: 'change',
    },
  ],
  resource: [
    {required: true, message: 'Please select activity resource', trigger: 'change',
    },
  ],
  email: [
    {
      required: true,
      message: '请输入电子邮箱',
      trigger: 'blur',
    },
    {
      pattern: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
      message: '请输入有效的电子邮箱地址',
      trigger: 'blur',
    },
  ],
  mobile: [
    {
      required: true,
      message: '请输入手机号',
      trigger: 'blur',
    },
    {
      pattern: /^1[3-9]\d{9}$/,
      message: '请输入有效的手机号',
      trigger: 'blur',
    },
  ],
})

const submitForm = async (formEl: FormInstance | undefined,submitType) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      console.log('submit!')
      ruleForm.honorTitleId = ruleForm.honorTitleId.join(',')
      ruleForm.submitType = submitType
      updatePersonList(ruleForm)
          .then((res)=>{
            console.log(res)
            if(res.code ==200){
              ElMessage({
                type: 'success',
                message: res.msg,
              })
              fathergeilist()
              dialogFormVisible.value = false
            }else {
              ElMessage({
                type: 'info',
                message: res.msg,
              })
            }
          })
    } else {
      console.log('error submit!', fields)
    }
  })
}

const resetForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return
  formEl.resetFields()
  dialogFormVisible.value = false
}
// 编辑

//最后学位
const zuihouxueweiOptions = [
  {
    value: '2',
    label: '博士',
  },
  {
    value: '3',
    label: '硕士',
  },
  {
    value: '4',
    label: '学士',
  },
  {
    value: '999',
    label: '无',
  },
]
//男女
const sex = [
  {
    value: '1',
    label: '男',
  },
  {
    value: '0',
    label: '女',
  },
]
//在职情况
const zaizhiqingkuangOptions = [
  {
    value: '1',
    label: '在职',
  },
  {
    value: '3',
    label: '离职',
  },
  {
    value: '2',
    label: '退休',
  },
]
//职称
const zhichengOptions = ref([])
//一级学科
const yijixuekeOptions = ref([])
//所属单位
const shuoshudanweiOptions = ref([])
//人事单位
const renshidanweiOptions = ref([])

//科学研究领域
const kexueyanjiuOptions = ref([])
const getkexueyanjiuOptions =function () {
  getCategory(
      {
        'bizName':'学科门类（学位）'
      }
  )
      .then((res)=>{

        kexueyanjiuOptions.value = res.data
      })
}
//政治面貌
const zhengzhimianmaoOptions = ref([])
const getzhengzhimianmaoOptions =function () {
  getCategory(
      {
        'bizName':'政治面貌'
      }
  )
      .then((res)=>{

        zhengzhimianmaoOptions.value = res.data
      })
}


//接受父组件state
const props = defineProps({
  state: {
    type: String,
    default: 100,
  },
})

watch(props,(val)=>{
  // console.log('接受父组件传给子组件的值value',props.state)
   if(props.state == 0){
     getListParme.value.checkstatus = ''
     fathergeilist(getListParme.value)
   }else {
     getListParme.value.checkstatus = props.state
     fathergeilist(getListParme.value)
   }

})
//console.log(props.state)
const getListParme = ref({
  checkstatus: "",//（全部传空，通过传2，退回传4，待审核传0）
  account:'', //职工号
  name:'', //姓名
  nameEn:'', //英文名
  sexIdList:[], //性别 0女  1男
  unitIdList:[], //所属单位
  hrUnitIdList:[], //人事单位
  eduDegreeIdList:[], //最后学位
  titleIdList:[], //职称
  subjectIdList:[], //一级学科
  mobile:'', //mobile
  email:'', //电子邮件
  researchFiel:'', //研究方向
  idCard:'', //身份证
  personStateList:[], //在职情况，在职 1，退休 2，离职 3
  graduateSchool:'',//毕业院校
  page:'1',
  pageSize:'10'
})
const init = () => {
}
init()
//获取职称下拉
const getzhichengOptions =function () {
  //职称
  getCategory(
      {
        'bizName':'职称单选'
      }
  )
      .then((res)=>{

        zhichengOptions.value = res.data
      })
}
const getyijixuekeOptions =function () {
  getCategory(
      {
        'bizName':'一级学科'
      }
  )
      .then((res)=>{

        yijixuekeOptions.value = res.data
      })
}
//成果归属单位
const getshuoshudanweiOptions =function () {
  getCategory(
      {
        'bizName':'成果归属单位'
      }
  )
      .then((res)=>{

        shuoshudanweiOptions.value = res.data
      })
}
const getrenshidanweiOptions =function () {
  getCategory(
      {
        'bizName':'所属人事单位'
      }
  )
      .then((res)=>{

        renshidanweiOptions.value = res.data
      })
}
//查询
const searchBtnList =function () {
  console.log(getListParme.value)
  getPersonList(getListParme.value)
      .then((res)=>{
        tableData.value = res.data.list
        count.value = res.data.count
        emit('GetprocessCount',getListParme.value)
      })
}

//分页
const count = ref(0)

const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`)
}
const handleCurrentChange = (val: string) => {
  getListParme.value.page = val
  getPersonList(getListParme.value)
      .then((res)=>{
        tableData.value = res.data.list
        count.value = res.data.count
      })
  console.log(`current page: ${val}`)
}

///查看详情
const activ = ref(false)
const obj = ref('')
const openpeopledetails = function (row){
  activ.value = true
  console.log(activ.value)
  obj.value = row.id
}

const fathergeilist = function (){
  getPersonList(getListParme.value)
      .then((res)=>{
        tableData.value = res.data.list
        count.value = res.data.count
        emit('GetprocessCount',getListParme.value)
      })
}

//跳转科研详情
import DetailsPageVue from './../../details/DialogdetailsPage.vue'
const DetailsPage = ref(null)
const GoDetailsPage = function (row){
  DetailsPage.value.openDialogDetailsPage(row.id)
}

// import { useRouter } from 'vue-router';
//
// const router = useRouter();
//
// const GoDetailsPage = function(row){
//   router.push({
//     path: '/researchdetails',
//     query: {
//       id: row.id
//     }
//   });
// }
const emit= defineEmits(['GetprocessCount'])

defineExpose({fathergeilist,Export})
onMounted(()=>{
  console.log(getListParme)
  getPersonList(getListParme.value)
      .then((res)=>{
        tableData.value = res.data.list
        count.value = res.data.count
      })
})
</script>

<style scoped lang="scss">
.flex-input{
  display: flex;
  //margin-right: 10px;
}
.flex-input > div{
  margin-right: 10px;
  width: 20%;
}
.sss > div{
  margin: 5px 3px;
  width: 19%;
}
.dialog-flex{
  display: flex;
}
.dialog-flex > div{
  width: 50%;
}
</style>